local ziluan = fk.CreateSkill {
  name = "lingling__ziluan",
  tags = { Skill.Compulsory }
}

Fk:loadTranslationTable{
  ["lingling__ziluan"] = "自乱",
  [":lingling__ziluan"] = "锁定技，当你使用【闪】后，你弃置两张牌，不足则全弃并失去1点体力。",

  ["#lingling__ziluan-discard"] = "自乱：你须弃置两张牌",
}

ziluan:addEffect(fk.CardUseFinished, {
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(ziluan.name) and data.card and data.card.trueName == "jink"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = player:getCardIds("he")
    if #cards > 2 then
      cards = room:askToDiscard(player, {
        min_num = 2,
        max_num = 2,
        include_equip = true,
        skill_name = ziluan.name,
        prompt = "#lingling__ziluan-discard",
        cancelable = false,
        skip = true
      })
    end
    room:throwCard(cards, ziluan.name, player, player)
    if #cards < 2 then
      room:loseHp(player, 1, ziluan.name)
    end
  end,
})

ziluan:addTest(function(room, me)
  FkTest.RunAddSkills(me, ziluan.name)
  local jink = room:printCard("jink")

  --- test1: 直接使用闪
  --- 期望: 失去1点体力
  FkTest.runInRoom(function ()
    room:useCard({
      from = me,
      tos = {},
      card = jink
    })
  end)
  lu.assertEquals(me:getLostHp(), 1)

  --- test2: 摸2，使用闪
  --- 期望: 手牌全弃
  FkTest.runInRoom(function ()
    me:drawCards(2)
    room:useCard({
      from = me,
      tos = {},
      card = jink
    })
  end)
  lu.assertEquals(me:getHandcardNum(), 0)
  lu.assertEquals(me:getLostHp(), 1)
end)

return ziluan
